/**********************************************
 * 
 * File Name				:	GenericLoggerBean.java
 * 
 * Last Changed Date		: 	$Date: 2009-08-01 11:12:53 +0800 (星期六, 01 八月 2009) $
 * 
 * Last Changed Revision	:	$Revision: 86 $
 * 
 * Last Changed Author		:	$Author: cfanboy $
 * 
 * File Header URL			:	$HeadURL: svn://www.svnhost.cn/Busi-Building/code/branch/src/com/busibuilding/common/interceptor/GenericLoggerBean.java $
 * 
 * ********************************************
 */

package com.busibuilding.common.interceptor;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * Class Name: GenericLoggerBean.java 
 * Description: This logger will log the enter and exit the methods
 * @author: YU Zhipeng
 * @version: 1.0
 * @since: 1.0
 * Date: 2009-07-09
 */

public class GenericLoggerBean {
	
	private static Logger logger = LogManager.getLogger("Application Log:");

	public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
		logger.info("Beginning method : " + joinPoint.getTarget().getClass()
				+ "." + joinPoint.getSignature().getName() + "()");
		long startTime = System.currentTimeMillis();
		try {
			Object result = joinPoint.proceed();
			return result;
		} catch (Exception e) {
			logger.info(joinPoint.getTarget().getClass() + "."
					+ joinPoint.getSignature().getName() + "() invoke error");
			logger.info("error info [" + e.getMessage() + "]");
			throw e;
		} finally {
			logger.info("Ending method : " + joinPoint.getTarget().getClass()
					+ "." + joinPoint.getSignature().getName() + "()");
			logger.info("Method invocation time : "
					+ (System.currentTimeMillis() - startTime) + " ms.");
		}
	}
}
